<!DOCTYPE html>
<html>
<head>

    <title>A basic example of AJAX</title>

    <meta name="description" content=" A basic example of a chart created using AJAX. It shows a simple example and there is little happening on the page so the source is easy to navigate." />
    <meta name="googlebot" content="NOODP">

    <!-- Include the RGraph libraries -->
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.line.js" ></script>
    <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

</head>

<body>

    <h1>A basic example of AJAX</h1>
    
    <p>
        This is a basic example of using AJAX to request the data from the server. The window.onload function initiates the AJAX request
        and then the callback function - DrawGraph() - takes the response and creates the chart.
    </p>

    <canvas id="cvs" width="600" height="250">[No canvas support]</canvas><br />
    
    <button onclick="RGraph.AJAX('/getdata.html', DrawGraph)">Rfresh data</button>

    <script>
        /**
        * Ths window.onload function initiates the AJAX request. The AJAX page is: http://www.rgraph.net/getdata.html
        * If you view this in your browser you'll see that all it does is output a sequence of numbers.
        */
        $(document).ready(function ()
        {
            RGraph.AJAX('/getdata.html', DrawGraph);
        })



        /**
        * This is the AJAX callback function. It splits up the response, converts it to numbers and then creates the chart.
        */
        function DrawGraph (response)
        {
            // The responseText is the output of the AJAX request
            var data = response;

            // Split the data up into an array
            data = data.split(',');

            // Convert the array of strings into an array of numbers
            for (var i=0; i<data.length; ++i) {
                data[i] = Number(data[i]);
            }
            
            // Reset the canvas
            RGraph.Reset(document.getElementById("cvs"));

            // Now draw the chart
            var line = new RGraph.Line({
                id: 'cvs',
                data: data,
                options: {
                    hmargin: 10,
                    linewidth: 2,
                    ymax: 100,
                    labels: ['Gary','Olga','Lewis','Rachel','Nathan','Matt','Kevin','Indigo','Lou','Pete']
                }
            }).draw()
        }
    </script>

    <p>
        <b>Note:</b>
        In October 2013 a new CSV reader was added to RGraph. It makes reading CSV files much easier. You can read about
        <a href="csv-file-reader.html">the new CSV reader</a> here.
    </p>

</body>
</html>